package com.ruoyi.activiti;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;


/*
全部流程实例的挂起和激活
流程定义为挂起状态下，该流程定义下将不允许启动新的流程实例，已经发起的该流程定义的流程实例不受影响（如果选择级联挂起则流程实例也会被挂起）。
类：SuspendProcessInstance
 */
public class SuspendProcessInstance {
    public static void main(String[] args) {
        //1.得到ProcessEngine对象
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        //2.得到RunService对象
        RepositoryService repositoryService = defaultProcessEngine.getRepositoryService();
        //3.查询流程定义对象
        ProcessDefinition holiday = repositoryService.createProcessDefinitionQuery().processDefinitionKey("myProcess_1").deploymentId("12501").singleResult();
        //4.得到当前流程定义的实例是否都为暂停状态
        boolean suspended = holiday.isSuspended();
        //5.判断
        if (suspended){//如果是暂停则激活
            repositoryService.activateProcessDefinitionById(holiday.getId());
            System.out.println("流程定义"+holiday.getId()+"激活");
        } else {//如果是激活则暂停
            repositoryService.suspendProcessDefinitionById(holiday.getId());//普通挂起
            repositoryService.suspendProcessDefinitionById(holiday.getId(),true,null);//级联挂起
            System.out.println("流程定义"+holiday.getId()+"挂起");
        }
    }
}

